package com.example.system.service.user;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.example.common.core.constants.Constants;
import com.example.common.core.domain.Result;
import com.example.common.core.enums.ResultCode;
import com.example.security.exception.ServiceException;
import com.example.system.domain.user.User;
import com.example.system.domain.user.dto.UserDTO;
import com.example.system.domain.user.dto.UserQueryDTO;
import com.example.system.domain.user.vo.UserVO;
import com.example.system.mapper.user.UserMapper;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author 23050
 * @version 1.0
 * @description: TODO
 * @date 2025/3/3 20:16
 */
@Service
@RefreshScope
public class UserServiceImpl implements UserService{



    @Resource
    private UserMapper userMapper;


    //获取用户列表
    @Override
    public List<UserVO> list(UserQueryDTO userQueryDTO) {
        PageHelper.startPage(userQueryDTO.getPageNum(),userQueryDTO.getPageSize());
        return userMapper.selectUserQueryList(userQueryDTO);
    }

    //修改用户状态
    @Override
    public int updateStatus(UserDTO userDTO) {
        User user = userMapper.selectById(userDTO.getUserId());
        if (BeanUtil.isEmpty(user)){
            throw new ServiceException(ResultCode.FAILED_USER_NOT_EXISTS);
        }
        user.setStatus(userDTO.getStatus());
        return userMapper.updateById(user);
    }


}
